﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace BrsdServer
{
    public partial class modifyUser : System.Web.UI.Page
    {
        public String strName = "";
        public String userKind = "";
        String strPwd = "";
        userInfoBLL userBll = new userInfoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((String)Session["nameSession"] == "" || (String)Session["pwdSession"] == ""
                || Session["nameSession"] == null || Session["pwdSession"] == null)
            {
                Response.Redirect("index.aspx");
                return;
            }
            strName = (String)Session["nameSession"];
            strPwd = (String)Session["pwdSession"];
            DataTable dt = userBll.LoadAllByUserAndPwnd(strName, strPwd);
            //用户类型
            if (dt.Rows.Count != 0)
            {
                int kind = Convert.ToInt32(dt.Rows[0][3]);
                if (kind == 10)
                {
                    userKind = "管理员";
                }
                else if (kind == 0)
                {
                    userKind = "普通用户";
                }
                else
                {
                    userKind = "代理商";
                }
            }
        }



        protected void submitBtn_Click(object sender, EventArgs e)
        {
            String scriptStr = "";
            if (txtOldPwd.Text!=strPwd)
            {
                scriptStr="<script>alert('您输入的密码不对，请再次输入！');</script>";
                ClientScript.RegisterStartupScript(this.GetType(), "xxx", scriptStr);
            }
            else
            {
                if (txtNewPwd.Text!=txtConfirmPwd.Text)
                {
                    scriptStr = "<script>alert('您输入的新密码匹配！');</script>";
                    ClientScript.RegisterStartupScript(this.GetType(), "xxx", scriptStr);
                } 
                else
                {
                    if (userBll.Update(strName, strPwd, txtNewPwd.Text, txtEmail.Text, txtTel.Text, txtAddr.Text)==1)
                    {
                        scriptStr = "<script>alert('您信息已修改成功！');</script>";
                        ClientScript.RegisterStartupScript(this.GetType(), "xxx", scriptStr);
                    }
                }
            }
        }
    }
}
